package com.dyh.quickdemo.demos.resTemplateInsp;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

/*
@Author=Joey Wheeler
@Date=2020/10/19 17:37
*/
@Slf4j
public class MyRetryIntercepter implements ClientHttpRequestInterceptor {

    static Timer timer = new Timer("MyRetryIntercepterRetryTimer", true);



    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
        log.info("MyRetryIntercepter.intercept");
        return execution.execute(request,body);
//        ClientHttpResponse clientHttpResponse = null;
//        try {
//            clientHttpResponse= execution.execute(request, body);
//        } catch (IOException e) {
//            try {
//                Thread.sleep(1000L);
//            } catch (InterruptedException e1) {
//
//            }
//            log.info("重试");
//            try {
//                clientHttpResponse = execution.execute(request,body);
//            } catch (IOException e1) {
//
//            }
//        }
//
//        return clientHttpResponse;

    }


}

/*
 ThreadKillTask task = new ThreadKillTask(3000L
                - System.currentTimeMillis());

        while (!Thread.interrupted()) {


                Thread.yield();
                        }

                        task.cancel();
*/
